From: Brion Vibber Date: Tue, 26 Apr 2005 09:52:11 +0000 (+0000) Subject: * (bug 1982) Fix loading of old text for section merging on edits. X-Git-Tag: 1.5.0alpha1~123 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=86ae9336018ee945c302c291e7f2bca66d5fb71f;p=lhc%2Fweb%2Fwiklou.git * (bug 1982) Fix loading of old text for section merging on edits. --- diff --git a/includes/Article.php b/includes/Article.php index 9666c98030..8a9ad87bb9 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -957,6 +957,8 @@ class Article { /** * Fetch and uncompress the text for a given revision. * Can ask by rev_id number or timestamp (set $field) + * FIXME: This function is broken. Eliminate all uses and remove. + * Use Revision class in place. */ function fetchRevisionText( $revId = null, $field = 'rev_id' ) { $fname = 'Article::fetchRevisionText'; @@ -986,12 +988,15 @@ class Article { function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) { $fname = 'Article::getTextOfLastEditWithSectionReplacedOrAdded'; - if( is_null( $edittime ) ) { - $oldtext = $this->fetchRevisionText(); - } else { - $oldtext = $this->fetchRevisionText( $edittime, 'rev_timestamp' ); - } if ($section != '') { + if( is_null( $edittime ) ) { + $rev = Revision::newFromTitle( $this->mTitle ); + } else { + $dbw =& wfGetDB( DB_MASTER ); + $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime ); + } + $oldtext = $rev->getText(); + if($section=='new') { if($summary) $subject="== {$summary} ==\n\n"; $text=$oldtext."\n\n".$subject.$text; diff --git a/includes/EditPage.php b/includes/EditPage.php index 1eb87ab937..eccf09b770 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -365,10 +365,12 @@ class EditPage { $userid = $wgUser->getID(); if ( $isConflict) { + wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime'\n" ); $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded( $this->section, $this->textbox1, $this->summary, $this->edittime); } else { + wfDebug( "EditPage::editForm getting section '$this->section'\n" ); $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded( $this->section, $this->textbox1, $this->summary); } diff --git a/includes/Revision.php b/includes/Revision.php index 67eb4be6fc..a42ccacbde 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -36,6 +36,7 @@ class Revision { * @param int $id * @return Revision * @access public + * @static */ function &newFromTitle( &$title, $id = 0 ) { if( $id ) { @@ -74,6 +75,27 @@ class Revision { 'page_id=rev_page' ) ); } + /** + * Load the revision for the given title with the given timestamp. + * WARNING: Timestamps may in some circumstances not be unique, + * so this isn't the best key to use. + * + * @param Database $db + * @param Title $title + * @param string $timestamp + * @return Revision + * @access public + * @static + */ + function &loadFromTimestamp( &$db, &$title, $timestamp ) { + return Revision::loadFromConds( + $db, + array( 'rev_timestamp' => $db->timestamp( $timestamp ), + 'page_id=rev_page', + 'page_namespace' => $title->getNamespace(), + 'page_title' => $title->getDbkey() ) ); + } + /** * Given a set of conditions, fetch a revision. *